package cn.sumpay.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.*;

/**
 * Created by Administrator on 2017/1/3.
 */
public class DataSourceUtil {
    static ComboPooledDataSource cpds=null;
    static{
        cpds = new ComboPooledDataSource("oracle");
    }


    public static Connection getConnection(){
        try {
            return cpds.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }


    public static void close(Connection conn, PreparedStatement pst, ResultSet rs){
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(pst!=null){
            try {
                pst.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) {
        Connection conn=getConnection();
        System.out.println(conn.getClass().getName());
        close(conn,null,null);
    }


}
